Page({
  data:{
    goods_score:{"curHdIndex":0},
    express_pack:{"curHdIndex":0},
    express_felling:{"curHdIndex":0},
    express_speed:{"curHdIndex":0},
    img:"/images/shouye_04.png",
    items:[],
    order_goods_id:'',
    content:""
  },

defaultTap(e){
  console.log(this.data);
},


  init(_order_goods_id){
    console.log(_order_goods_id);    
       var app = getApp()
            var url = app.globadData.apiUrlHeader+'get-discount';
            var id = _order_goods_id;
            this.data.order_goods_id = id;
            this.setData({
              order_goods_id : id
            });
            id = '01fbe191-212f-11e8-aacd-6c0b8481e2be';
               my.httpRequest({
                   url: url, // 目标服务器 url
                   method:'Post',
                   headers:{'Content-Type':'Application/json'},
                   data:JSON.stringify({
                      "order_goods_id":id,
                      "access_token":app.globadData.access_token
                    }),
                  dataType:'json',
                  success: (res) => {
                   console.log(res.data.data.discount.goods_score);
                   var jj = {"curHdIndex":0};
                    if(res.data.status != 0){
                      this.setData({
                        order_goods_id : id,
                        goods_score: res.data.data.discount.goods_score                       
                      });
                    }
                    
                   },
               });

  },


chooseicon(e){
    console.log(e);
    console.log(e.target.dataset);
    var strnumber=e.target.dataset.id; 
   var _obj={};
    _obj.curHdIndex=strnumber; 
    this.setData({ 
     goods_score: _obj
    }); 
  },
  
  //物流包装评价
  chooseicon1(e){
    console.log(e);
    console.log(e.target.dataset);
    var strnumber=e.target.dataset.id; 
   var _obj={};
    _obj.curHdIndex=strnumber; 
    this.setData({ 
     express_pack: _obj
    }); 
  },
  
  //送货速度评价
   chooseicon2(e){
    console.log(e);
    console.log(e.target.dataset);
    var strnumber=e.target.dataset.id; 
   var _obj={};
    _obj.curHdIndex=strnumber; 
    this.setData({ 
     express_speed: _obj
    }); 
  },
  
  //配送员态度
     chooseicon3(e){
    console.log(e);
    console.log(e.target.dataset);
    var strnumber=e.target.dataset.id; 
   var _obj={};
    _obj.curHdIndex=strnumber; 
    this.setData({ 
     express_felling: _obj
    }); 
 },
  onLoad(query) {

    var order_goods_id = query.order_goods_id;
    this.init(order_goods_id);
  },


  formSubmit: function(e){
    var app = getApp()
    
    console.log(e);
    var discount_content = e.detail.value.__unknown_for_control_1;
    var id = this.data.order_goods_id;
    console.log(discount_content);
    console.log(this.data.goods_score);
    console.log(this.data.order_goods_id);
    if(discount_content == '' || discount_content == undefined)
      discount_content = '默认好平';
    var data = {
          "content":discount_content,
          "order_goods_id":this.data.order_goods_id,
          "goods_score":this.data.goods_score.curHdIndex,
          "express_pack":this.data.express_pack.curHdIndex,
          "express_speed":this.data.express_speed.curHdIndex,
          "express_felling":this.data.express_felling.curHdIndex,
          "access_token":app.globadData.access_token
        };
        console.log(data);

            var url = app.globadData.apiUrlHeader+'add-discount';
           
               my.httpRequest({
                   url: url, // 目标服务器 url
                   method:'Post',
                   headers:{'Content-Type':'Application/json'},
                   data:JSON.stringify(data),
                  dataType:'json',
                  success: (res) => {
                   console.log(res.data);
                       my.showToast({
                         content: '评论成功！', // 文字内容
                         success: (res) => {
                           my.navigateTo(
                             {
      url: `/pages/main/order-list/order-list`, // 需要跳转的 tabBar 页面的路径（需在 app.json 的 tabBar 字段定义的页面），路径后不能带参数
    });
                         },
                       });
                    
                   },
               });


  },

 
  photoTap(e){
    my.chooseImage({
      count : 9,
      success: (res) => {
        console.log(res);
        var arrary = [];
        res.apFilePaths.forEach(function(path) {
          // var pa = {"src":path};
          arrary.push(path);
        }, this);

        this.setData({
          items : arrary
        });

        // my.uploadFile({
        //   url: '', // 开发者服务器地址
        //   filePath: '', // 要上传文件资源的本地定位符
        //   fileName: '', // 文件名，即对应的 key, 开发者在服务器端通过这个 key 可以获取到文件二进制内容
        //   fileType: '', // 文件类型，image/video
        //   success: (res) => {
            
        //   },
        // });
        // this.data.items[0].src = res.apFilePaths[0];

      },
    });
  }


});
